<?php
$bar_active = 'tablet';
$current_url = '/'.$_GET['alias'].'/';
if($_GET['catalias'] == '') {
   $query_cat = '';
   $curr_cat = '';
   $seo_meta = get_seo_meta(0,'categories','Máy tính bảng','Hệ thống bán lẻ máy tính bảng số 1 Việt Nam. Chuyên bán lẻ máy tính bảng, Nokia, Samsung, iPhone, LG, HTC, BlackBerry,... mới chính hãng, giá tốt');
}else {
   $query_cat = ' AND cat_alias = "'.$_GET['catalias'].'"';
   $curr_cat = db_first('SELECT * FROM categories WHERE cat_alias = "'.$_GET['catalias'].'"');
   if(!$curr_cat) not_found();
   $seo_meta = get_seo_meta($curr_cat['cat_id'],'categories',$curr_cat['cat_name'],'Hệ thống bán lẻ máy tính bảng số 1 Việt Nam. Chuyên bán lẻ máy tính bảng, Nokia, Samsung, iPhone, LG, HTC, BlackBerry,... mới chính hãng, giá tốt');
}
//sap xep gia
$filter_price = getValue('gia','str','GET','');
$filter_os = getValue('hdh','str','GET','');
$filter_display = getValue('man','str','GET','');
$filter_feature = getValue('tn','str','GET','');
$filter_view = getValue('sx','str','GET','');
$tt_os = '&';
$tt_display = '&';
$tt_feature = '&';
$tt_view = '&';
switch($filter_price) {
   case 'duoi-1-trieu':
      $query_price = ' AND pro_price <= 1000000';
      $current_filter_price = 'gia=duoi-1-trieu';
      break;
   case 'duoi-2-trieu':
      $query_price = ' AND pro_price <= 2000000';
      $current_filter_price = 'gia=duoi-2-trieu';
      break;
   case 'duoi-3-trieu':
      $query_price = ' AND pro_price <= 3000000';
      $current_filter_price = 'gia=duoi-3-trieu';
      break;
   case 'duoi-5-trieu':
      $query_price = ' AND pro_price <= 5000000';
      $current_filter_price = 'gia=duoi-5-trieu';
      break;
   case 'duoi-8-trieu':
      $query_price = ' AND pro_price <= 8000000';
      $current_filter_price = 'gia=duoi-8-trieu';
      break;
   case 'duoi-10-trieu':
      $query_price = ' AND pro_price <= 10000000';
      $current_filter_price = 'gia=duoi-10-trieu';
      break;
   case 'tren-10-trieu':
      $query_price = ' AND pro_price >= 10000000';
      $current_filter_price = 'gia=tren-10-trieu';
      break;
   default:
      $query_price = '';
      $current_filter_price = '';
      break;
}
switch($filter_os) {
   case 'android':
      $query_os = ' AND pro_general_os = "android"';
      $current_filter_os = 'hdh=android';
      break;
   case 'ios':
      $query_os = ' AND pro_general_os = "ios"';
      $current_filter_os = 'hdh=ios';
      break;
   case 'windows':
      $query_os = ' AND pro_general_os = "windows"';
      $current_filter_os = 'hdh=windows';
      break;
   case 'other':
      $query_os = ' AND pro_general_os = "other"';
      $current_filter_os = 'hdh=other';
      break;
   default:
      $query_os = '';
      $current_filter_os = '';
      break;
}
switch($filter_display) {
   case 'duoi-3':
      $query_display = ' AND pro_display_width <= 3';
      $current_filter_display = 'man=duoi-3';
      break;
   case 'khoang-3':
      $query_display = ' AND pro_display_width >= 3 AND pro_display_width <= 4';
      $current_filter_display = 'man=khoang-3';
      break;
   case 'khoang-4':
      $query_display = ' AND pro_display_width >= 4 AND pro_display_width <= 5';
      $current_filter_display = 'man=khoang-4';
      break;
   case 'khoang-5':
      $query_display = ' AND pro_display_width >= 5 AND pro_display_width <= 6';
      $current_filter_display = 'man=khoang-5';
      break;
   case 'khoang-6':
      $query_display = ' AND pro_display_width >= 6';
      $current_filter_display = 'man=khoang-6';
      break;
   default:
      $query_display = '';
      $current_filter_display = '';
      break;
}
switch($filter_feature) {
   case 'bang-tan-3g-4g':
      $query_feature = ' AND pro_connect_3g != ""';
      $current_filter_feature = 'tn=bang-tan-3g-4g';
      break;
   case '2-sim-2-song':
      $query_feature = ' AND pro_connect_duasim != ""';
      $current_filter_feature = 'tn=2-sim-2-song';
      break;
   case 'smartphone':
      $query_feature = ' AND pro_display_induction != ""';
      $current_filter_feature = 'tn=smartphone';
      break;
   case 'wifi':
      $query_feature = ' AND pro_connect_wifi != ""';
      $current_filter_feature = 'tn=wifi';
      break;
   case 'cam-ung':
      $query_feature = ' AND pro_display_induction != ""';
      $current_filter_feature = 'tn=cam-ung';
      break;
   default:
      $query_feature = '';
      $current_filter_feature = '';
      break;
}
switch($filter_view) {
   case 'xem-nhieu-nhat':
      $query_view = 'ORDER BY pro_view DESC';
      $current_filter_view = 'sx=xem-nhieu-nhat';
      break;
   case 'gia-cao-den-thap':
      $query_view = 'ORDER BY pro_price DESC';
      $current_filter_view = 'sx=gia-cao-den-thap';
      break;
   case 'gia-thap-den-cao':
      $query_view = 'ORDER BY pro_price ASC';
      $current_filter_view = 'sx=gia-thap-den-cao';
      break;
   default:
      $query_view = '';
      $current_filter_view = '';
      break;
}

if($filter_price == '' && $filter_os == '' && $filter_display == '' && $filter_feature == '' && $filter_view == '') {
   $tt_os = '';
   $tt_display = '';
   $tt_feature = '';
   $tt_view = '';
}elseif($filter_os == '' && $filter_display == '' && $filter_feature == '' && $filter_view == '') {
   $tt_display = '';
   $tt_feature = '';
   $tt_view = '';
}

$list_products = db_array('SELECT *
                           FROM products
                           LEFT JOIN categories ON pro_cat_id = cat_id
                           WHERE pro_active = 1 AND pro_type = 2'.$query_cat.$query_price.$query_os.$query_display.$query_feature.' 
                           '.$query_view.'
                           LIMIT 20');
$total_products = count($list_products);

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="vi-VN" lang="vi-VN" xmlns:og="http://ogp.me/ns#" xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
   <link href="<?=DOMAIN?>/favicon.ico" type="image/x-icon" rel="shortcut icon"/>
   <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
   <?php echo $seo_meta;?>
   <!-- css -->
   <link rel="stylesheet" type="text/css" href="/themes/css/base.css"/>
   <link rel="stylesheet" type="text/css" href="/themes/css/product.css"/>
   <link rel="stylesheet" type="text/css" href="/themes/css/mobile.css"/>

   <script type="text/javascript" src="/themes/js/jquery-1.9.0.min.js"></script>
   <script type="text/javascript" src="/themes/js/site.js"></script>
   <?=$facebook_script?>
</head>
<body>
   <?php include 'view/view_header.php'?>
   <?php include 'view/view_tablets.php'?>
   <?php include 'view/view_support.php'?>
   <?php include 'view/view_footer.php'?>
</body>
</html>